package cn.edu.lzu.service.impl;

import cn.edu.lzu.common.assist.*;
import cn.edu.lzu.common.util.DetectUtil;
import cn.edu.lzu.dao.*;
import cn.edu.lzu.entity.*;
import cn.edu.lzu.service.BookRegisteService;
import cn.edu.lzu.service.ExamineItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.awt.print.Book;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @PackageName: cn.edu.lzu.service.impl
 * @ClassName: BookRegisteServiceImpl
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/3/9 21:55
 * @Version: 1.0
 */
@Service
@Transactional
public class BookRegisteServiceImpl implements BookRegisteService {
    @Resource
    private BookRegisteMapper bookRegisteMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private ExaminePackageMapper examinePackageMapper;
    @Resource
    private ExamineItemMapper examineItemMapper;
    @Resource
    private ExaminerMapper examinerMapper;
    @Resource
    private ItemPackageMapper itemPackageMapper;
    @Resource
    private FillLabItemMapper fillLabItemMapper;
    @Resource
    private RadiologyExamineItemMapper radiologyExamineItemMapper;
    @Resource
    private FillRadItemMapper fillRadItemMapper;
    @Resource
    private SpeculumExamineItemMapper speculumExamineItemMapper;
    @Resource
    private FillSpeItemMapper fillSpeItemMapper;
    @Resource
    private SupersonicExamineItemMapper supersonicExamineItemMapper;
    @Resource
    private FillSupItemMapper fillSupItemMapper;
    @Resource
    private MedicalExamineItemMapper medicalExamineItemMapper;
    @Resource
    private FillMedItemMapper fillMedItemMapper;
    @Resource
    private ClinicExamineItemMapper clinicExamineItemMapper;
    @Resource
    private FillCliItemMapper fillCliItemMapper;
    @Resource
    private TotalExamineMapper totalExamineMapper;


    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 获取一页挂号数据
     * @Date: 2020/3/9 21:56
     * @Param: [currentPageNum, pageSize, unitId]
     * @Return: cn.edu.lzu.common.assist.DataPage
     **/
    @Override
    public DataPage getRegisteUserList(int currentPageNum, int pageSize, long unitId) {
        //新的一页开始下标
        int startIndex = (currentPageNum - 1) * pageSize;
        //一页数据
        List<BookRegiste> bookRegisteList = bookRegisteMapper.selPageRegisteUserList(startIndex, pageSize, unitId);
        List<BookRegisteTableAssist> bookRegisteTableAssistList = getBookRegisteTableAssistList(bookRegisteList);
        DataPage dataPage = new DataPage();
        dataPage.setData(bookRegisteTableAssistList);
        dataPage.setTotalCount(bookRegisteMapper.selCountRegiste(unitId));
        dataPage.setCode(0);
        dataPage.setMsg("数据获取成功！");
        return dataPage;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 挂号页面根据模糊搜索的输入获取相对应的数据
     * @Date: 2020/3/10 12:37
     * @Param: [searchUserInput]
     * @Return: cn.edu.lzu.common.assist.DataPage
     **/
    @Override
    public DataPage getRegisteUserListBySearchInput(String searchUserInput, long unitId, int pageSize) {
        // 如果输入字段的长度小于18位，并且可以被解析成数字，那么认为它是身份证号，否则为姓名；
        // 如果输入字段的长度等于18位，检测是不是身份证号，如果不是则认为是姓名；
        // 如果大于18位，则认为是姓名
        List<BookRegiste> bookRegisteList;
        int totalCount = 0;
        if (searchUserInput.length() < 18) {
            if (DetectUtil.isNumber(searchUserInput)) {
                bookRegisteList = bookRegisteMapper.selFuzzyByUserIdentity(unitId, searchUserInput, pageSize);
                totalCount = bookRegisteMapper.selFuzzyCountByUserIdentity(unitId, searchUserInput);
            } else {
                //bookRegisteList=bookRegisteMapper.selFuzzyByUserName(unitId, searchUserInput, pageSize);
                //totalCount=bookRegisteMapper.selFuzzyCountByUserName(unitId, searchUserInput);
                bookRegisteList = new ArrayList<>();
                totalCount = 0;
            }
        } else if (searchUserInput.length() == 18) {
            if (DetectUtil.isIdNumber(searchUserInput)) {
                bookRegisteList = bookRegisteMapper.selFuzzyByUserIdentity(unitId, searchUserInput, pageSize);
                totalCount = bookRegisteMapper.selFuzzyCountByUserIdentity(unitId, searchUserInput);
            } else {
                //bookRegisteList=bookRegisteMapper.selFuzzyByUserName(unitId, searchUserInput, pageSize);
                //totalCount=bookRegisteMapper.selFuzzyCountByUserName(unitId, searchUserInput);
                bookRegisteList = new ArrayList<>();
                totalCount = 0;
            }

        } else {
            //bookRegisteList=bookRegisteMapper.selFuzzyByUserName(unitId, searchUserInput, pageSize);
            bookRegisteList = new ArrayList<>();
            totalCount = 0;
        }

        List<BookRegisteTableAssist> bookRegisteTableAssistList = getBookRegisteTableAssistList(bookRegisteList);

        System.out.println("bookRegisteTableAssistList:" + bookRegisteTableAssistList);

        DataPage dataPage = new DataPage();
        dataPage.setData(bookRegisteTableAssistList);
        dataPage.setTotalCount(totalCount);
        dataPage.setCode(0);
        dataPage.setMsg("数据获取成功！");
        return dataPage;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 获取所有挂号记录的缴费信息
     * @Date: 2020/3/11 23:02
     * @Param: [currentPageNum, pageSize, unitId]
     * @Return: cn.edu.lzu.common.assist.DataPage
     **/
    @Override
    public DataPage getAllUserChargeMsgList(int currentPageNum, int pageSize, long unitId, int tableType) {
        //新的一页开始下标
        int startIndex;
        //一页数据
        List<BookRegiste> bookRegisteList = new ArrayList<>();
        int totalCount = 0;
        //循环的目的：当本页数据为0且本页不是第一页时，回退到前一页。
        do {
            System.out.println("currentPageNum:" + currentPageNum);
            currentPageNum = currentPageNum - 1;
            startIndex = currentPageNum * pageSize;
            if (tableType == 1) {
                bookRegisteList = bookRegisteMapper.selUnchangedUserList(startIndex, pageSize, unitId);
                totalCount = bookRegisteMapper.selUnchargedUserChargeMsgCount(unitId);
            } else if (tableType == 2) {
                bookRegisteList = bookRegisteMapper.selChangedUserList(startIndex, pageSize, unitId);
                totalCount = bookRegisteMapper.selChargedUserChargeMsgCount(unitId);
            } else if (tableType == 3) {
                bookRegisteList = bookRegisteMapper.selPageAllUserList(startIndex, pageSize, unitId);
                totalCount = bookRegisteMapper.selAllUserChargeMsgCount(unitId);
            }
        } while (currentPageNum >= 1 && bookRegisteList.size() == 0);

        List<AllUserChargeMsgAssist> allUserChargeMsgAssistList = getAllUserChargeMsgAssistList(bookRegisteList);
        DataPage dataPage = new DataPage();
        dataPage.setData(allUserChargeMsgAssistList);
        dataPage.setTotalCount(totalCount);
        dataPage.setCode(0);
        dataPage.setMsg("数据获取成功！");
        return dataPage;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 缴费页面所有用户的缴费信息table的模糊搜索
     * @Date: 2020/3/12 16:31
     * @Param: [currentPageNum, pageSize, unitId]
     * @Return: cn.edu.lzu.common.assist.DataPage
     **/
    @Override
    public DataPage getAllUserChargeMsgListBySearchInput(String searchAllUserChargeMsgInput, long unitId, int pageSize, int tableType) {
        List<BookRegiste> bookRegisteList = new ArrayList<>();
        int totalCount = 0;
        if (searchAllUserChargeMsgInput.length() < 18) {
            if (DetectUtil.isNumber(searchAllUserChargeMsgInput)) {
                if (tableType == 1) {
                    bookRegisteList = bookRegisteMapper.selFuzzyUnchargedUserChargeMsgByUserIdentity(unitId, searchAllUserChargeMsgInput, pageSize);
                    totalCount = bookRegisteMapper.selFuzzyUnchangedUserChargeMsgCountByUserIdentity(unitId, searchAllUserChargeMsgInput);
                } else if (tableType == 2) {
                    bookRegisteList = bookRegisteMapper.selFuzzyChargedUserChargeMsgByUserIdentity(unitId, searchAllUserChargeMsgInput, pageSize);
                    totalCount = bookRegisteMapper.selFuzzyChargedUserChargeMsgCountByUserIdentity(unitId, searchAllUserChargeMsgInput);
                } else if (tableType == 3) {
                    bookRegisteList = bookRegisteMapper.selFuzzyAllUserChargeMsgByUserIdentity(unitId, searchAllUserChargeMsgInput, pageSize);
                    totalCount = bookRegisteMapper.selFuzzyAllUserChargeMsgCountByUserIdentity(unitId, searchAllUserChargeMsgInput);
                }
            } else {
                bookRegisteList = new ArrayList<>();
                totalCount = 0;
            }
        } else if (searchAllUserChargeMsgInput.length() == 18) {
            System.out.println("是身份证号吗：" + DetectUtil.isIdNumber(searchAllUserChargeMsgInput));
            if (DetectUtil.isIdNumber(searchAllUserChargeMsgInput)) {
                if (tableType == 1) {
                    bookRegisteList = bookRegisteMapper.selFuzzyUnchargedUserChargeMsgByUserIdentity(unitId, searchAllUserChargeMsgInput, pageSize);
                    totalCount = bookRegisteMapper.selFuzzyUnchangedUserChargeMsgCountByUserIdentity(unitId, searchAllUserChargeMsgInput);
                } else if (tableType == 2) {
                    bookRegisteList = bookRegisteMapper.selFuzzyChargedUserChargeMsgByUserIdentity(unitId, searchAllUserChargeMsgInput, pageSize);
                    totalCount = bookRegisteMapper.selFuzzyChargedUserChargeMsgCountByUserIdentity(unitId, searchAllUserChargeMsgInput);
                } else if (tableType == 3) {
                    bookRegisteList = bookRegisteMapper.selFuzzyAllUserChargeMsgByUserIdentity(unitId, searchAllUserChargeMsgInput, pageSize);
                    totalCount = bookRegisteMapper.selFuzzyAllUserChargeMsgCountByUserIdentity(unitId, searchAllUserChargeMsgInput);
                }
            } else {
                bookRegisteList = new ArrayList<>();
                totalCount = 0;
            }
        } else {
            bookRegisteList = new ArrayList<>();
            totalCount = 0;
        }
        List<AllUserChargeMsgAssist> allUserChargeMsgAssistList = getAllUserChargeMsgAssistList(bookRegisteList);
        DataPage dataPage = new DataPage();
        dataPage.setData(allUserChargeMsgAssistList);
        dataPage.setTotalCount(totalCount);
        dataPage.setCode(0);
        dataPage.setMsg("数据获取成功！");
        return dataPage;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 处理缴费的业务逻辑
     * @Date: 2020/3/14 22:34
     * @Param: [id]
     * @Return: cn.edu.lzu.common.assist.ResponseResult
     **/
    @Override
    public ResponseResult handleChargeOperation(int id) {
        int result = bookRegisteMapper.updSetChargedTrue(id);
        ResponseResult responseResult = new ResponseResult();
        if (result == 1) {
            responseResult.setCode(1);
            responseResult.setMsg("缴费成功！");
        } else {
            responseResult.setCode(0);
            responseResult.setMsg("缴费失败！");
        }
        return responseResult;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 获取“实验室检查”页面table的数据
     * @Date: 2020/3/16 17:45
     * @Param: [searchBookRegisteInput]
     * @Return: cn.edu.lzu.common.assist.DataPage
     **/
    @Override
    public DataPage getExamineItemTableMsgDataPage(Integer searchBookRegisteInput, String examinetype) {
        if (searchBookRegisteInput == null || searchBookRegisteInput == -1) {
            DataPage dataPage = new DataPage();
            dataPage.setData(new ArrayList());
            dataPage.setMsg("无数据");
            dataPage.setCode(0);
            return dataPage;
        } else {
            DataPage dataPage = new DataPage();
            BookRegiste bookRegiste = bookRegisteMapper.selBookRegisteById(searchBookRegisteInput);
            if (bookRegiste == null) {
                dataPage.setData(new ArrayList());
                dataPage.setMsg("无数据");
                dataPage.setCode(0);
                return dataPage;
            }
            //根据检查类型examineType获取该套餐包含的该检查类型的项目
            List<ItemPackage> itemPackageList = itemPackageMapper.selItemPackagesByPackageId(bookRegiste.getExaminePackageId(), examinetype);
            dataPage.setTotalCount(itemPackageList.size());
            List<ItemTableAssist> itemTableAssistList = new ArrayList<>();

            switch (examinetype) {
                case "lab":
                    itemTableAssistList = getLabItems(itemPackageList, bookRegiste);
                    break;
                case "rad":
                    itemTableAssistList = getRadItems(itemPackageList, bookRegiste);
                    break;
                case "spe":
                    itemTableAssistList = getSpeItems(itemPackageList, bookRegiste);
                    break;
                case "sup":
                    itemTableAssistList = getSupItems(itemPackageList, bookRegiste);
                    break;
                case "cli":
                    itemTableAssistList = getCliItems(itemPackageList, bookRegiste);
                    break;
                case "med":
                    itemTableAssistList = getMedItems(itemPackageList, bookRegiste);
                    break;
            }
            dataPage.setCode(0);
            dataPage.setMsg("数据获取成功！");
            dataPage.setData(itemTableAssistList);
            return dataPage;
        }
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 受检查人员信息
     * @Date: 2020/3/16 21:20
     * @Param: [id]
     * @Return: java.util.Map<java.lang.String, java.lang.Object>
     **/
    @Override
    public Map<String, Object> getRegisteUserMsg(Integer id) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if (id == null || id <= 0) {
            hashMap.put("code", 0);
            return hashMap;
        } else {
            BookRegiste bookRegiste = bookRegisteMapper.selBookRegisteById(id);
            if (bookRegiste == null) {
                hashMap.put("code", 0);
                return hashMap;
            }
            User user = userMapper.selUserByIdentityAndTrue(bookRegiste.getUserIdentity());
            Examiner examiner = examinerMapper.selExaminerById(bookRegiste.getExaminerId());
            hashMap.put("bookRegiste", bookRegiste);
            hashMap.put("user", user);
            hashMap.put("examiner", examiner);
            hashMap.put("code", 1);
            return hashMap;
        }
    }

    @Override
    public ResponseResult submitTotalExamineResult(TotalExamine totalExamine, Examiner examiner) {
        int result=totalExamineMapper.insTotalExamine(totalExamine, examiner);
        int updUserStatus=bookRegisteMapper.updUserStatus(3, totalExamine.getBookRegisteId());
        ResponseResult responseResult=new ResponseResult();
        if(result==1 && updUserStatus==1){
            responseResult.setCode(1);
            responseResult.setMsg("总检完成！");
        }else{
            responseResult.setCode(0);
            responseResult.setMsg("总检失败！");
        }
        return responseResult;
    }

    @Override
    public DataPage getBookedUser(int currentPageNum, long unitId, Integer pageSize) {
        //新的一页开始下标
        int startIndex = (currentPageNum - 1) * pageSize;
        //一页数据
        List<BookRegiste> bookRegisteList = bookRegisteMapper.selBookedUser(startIndex, pageSize, unitId);
        List<BookRegisteTableAssist> bookRegisteTableAssistList = getBookedTableAssistList(bookRegisteList);
        DataPage dataPage = new DataPage();
        dataPage.setData(bookRegisteTableAssistList);
        dataPage.setTotalCount(bookRegisteMapper.selCountBooked(unitId));
        dataPage.setCode(0);
        dataPage.setMsg("数据获取成功！");
        return dataPage;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 通过给定的bookRegistelist获取bookRegisteTableAssistList
     * @Date: 2020/3/10 15:10
     * @Param: [bookRegisteList]
     * @Return: java.util.List<cn.edu.lzu.common.assist.BookRegisteTableAssist>
     **/
    private List<BookRegisteTableAssist> getBookRegisteTableAssistList(List<BookRegiste> bookRegisteList) {
        List<BookRegisteTableAssist> bookRegisteTableAssistList = new ArrayList<>();
        for (int i = 0; i < bookRegisteList.size(); i++) {
            BookRegisteTableAssist bookRegisteTableAssist = new BookRegisteTableAssist();
            bookRegisteTableAssist.setExamineDate(bookRegisteList.get(i).getBookDate());
            bookRegisteTableAssist.setUserIdentity(bookRegisteList.get(i).getUserIdentity());
            bookRegisteTableAssist.setId(bookRegisteList.get(i).getId());
            //根据身份证号获取用户姓名
            User user = userMapper.selUserByIdentityAndTrue(bookRegisteList.get(i).getUserIdentity());
            bookRegisteTableAssist.setUserName(user.getUserName());
            //根据套餐编号获取套餐名
            ExaminePackage examinePackage = examinePackageMapper.selExaminePackageById(bookRegisteList.get(i).getExaminePackageId());
            bookRegisteTableAssist.setExaminePackageName(examinePackage.getPackageName());
            //根据examiner的id获取其姓名
            Examiner examiner = examinerMapper.selExaminerByIdFromAll(bookRegisteList.get(i).getExaminerId());
            bookRegisteTableAssist.setExaminerName(examiner.getExaminerName());
            bookRegisteTableAssistList.add(bookRegisteTableAssist);
        }
        return bookRegisteTableAssistList;
    }

    //预约列表
    private List<BookRegisteTableAssist> getBookedTableAssistList(List<BookRegiste> bookRegisteList) {
        List<BookRegisteTableAssist> bookRegisteTableAssistList = new ArrayList<>();
        for (int i = 0; i < bookRegisteList.size(); i++) {
            BookRegisteTableAssist bookRegisteTableAssist = new BookRegisteTableAssist();
            bookRegisteTableAssist.setExamineDate(bookRegisteList.get(i).getBookDate());
            bookRegisteTableAssist.setUserIdentity(bookRegisteList.get(i).getUserIdentity());
            bookRegisteTableAssist.setId(bookRegisteList.get(i).getId());
            //根据身份证号获取用户姓名
            User user = userMapper.selUserByIdentityAndTrue(bookRegisteList.get(i).getUserIdentity());
            bookRegisteTableAssist.setUserName(user.getUserName());
            //根据套餐编号获取套餐名
            ExaminePackage examinePackage = examinePackageMapper.selExaminePackageById(bookRegisteList.get(i).getExaminePackageId());
            bookRegisteTableAssist.setExaminePackageName(examinePackage.getPackageName());

            bookRegisteTableAssist.setExaminerName("网上预约");
            bookRegisteTableAssistList.add(bookRegisteTableAssist);
        }
        return bookRegisteTableAssistList;
    }

    /**
     * @Author: 张琦[QQ:3098086691]
     * @Description: TODO 通过给定的bookRegistelist获取allUserChargeMsgAssistList
     * @Date: 2020/3/12 16:27
     * @Param: [bookRegisteList]
     * @Return: java.util.List<cn.edu.lzu.common.assist.AllUserChargeMsgAssist>
     **/
    private List<AllUserChargeMsgAssist> getAllUserChargeMsgAssistList(List<BookRegiste> bookRegisteList) {
        List<AllUserChargeMsgAssist> allUserChargeMsgAssistList = new ArrayList<>();
        for (int i = 0; i < bookRegisteList.size(); i++) {
            AllUserChargeMsgAssist allUserChargeMsgAssist = new AllUserChargeMsgAssist();
            allUserChargeMsgAssist.setExamineDate(bookRegisteList.get(i).getBookDate());
            allUserChargeMsgAssist.setUserIdentity(bookRegisteList.get(i).getUserIdentity());
            allUserChargeMsgAssist.setId(bookRegisteList.get(i).getId());
            //根据身份证号获取用户姓名
            User user = userMapper.selUserByIdentityAndTrue(bookRegisteList.get(i).getUserIdentity());
            allUserChargeMsgAssist.setUserName(user.getUserName());
            //根据套餐编号获取套餐名和套餐价格
            ExaminePackage examinePackage = examinePackageMapper.selExaminePackageById(bookRegisteList.get(i).getExaminePackageId());
            allUserChargeMsgAssist.setExaminePackageName(examinePackage.getPackageName());
            allUserChargeMsgAssist.setExaminePackagePrice(examinePackage.getPrice());
            //根据examiner的id获取其姓名
            Examiner examiner = examinerMapper.selExaminerByIdFromAll(bookRegisteList.get(i).getExaminerId());
            allUserChargeMsgAssist.setExaminerName(examiner.getExaminerName());
            //应付款额=套餐价格+额外项目价格
            allUserChargeMsgAssist.setTotalPrice(examinePackage.getPrice() + 0);
            //设置缴费状态
            allUserChargeMsgAssist.setChargeStatus(bookRegisteList.get(i).isCharged());
            allUserChargeMsgAssistList.add(allUserChargeMsgAssist);

        }
        return allUserChargeMsgAssistList;
    }

    private List<ItemTableAssist> getLabItems(List<ItemPackage> itemPackageList, BookRegiste bookRegiste) {
        List<ItemTableAssist> itemTableAssistList = new ArrayList<>();
        //如果fillLabItem中没有创建item对应的记录，则创建，否则直接显示。
        for (int i = 0; i < itemPackageList.size(); i++) {
            ItemPackage itemPackage = itemPackageList.get(i);
            //获取一个具体的项目信息
            ExamineItem examineItem = examineItemMapper.selByExamineItemId(itemPackage.getExamineItemId());
            ItemTableAssist itemTableAssist = new ItemTableAssist();
            //将必要的项目信息存入itemTabelAssist
            itemTableAssist.setExamineItemId(examineItem.getExamineItemId());
            itemTableAssist.setItemName(examineItem.getExamineName());
            itemTableAssist.setBookRegisteId(bookRegiste.getId());
            //获取存储检查数据的记录，如果不存在，怎新建一条记录
            FillLabItem fillLabItem = fillLabItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), itemPackageList.get(i).getExamineItemId());
            if (fillLabItem != null) {
                itemTableAssist.setFilledStatus(fillLabItem.isFilled());
                itemTableAssist.setFillItemId(fillLabItem.getFillLabItemId());
            } else {
                fillLabItemMapper.insFillLabItem(bookRegiste.getId(), examineItem.getExamineItemId());
                itemTableAssist.setFilledStatus(false);
                FillLabItem fillLabItem1 = fillLabItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), itemPackageList.get(i).getExamineItemId());
                itemTableAssist.setFillItemId(fillLabItem1.getFillLabItemId());
            }
            itemTableAssistList.add(itemTableAssist);
        }
        return itemTableAssistList;
    }

    private List<ItemTableAssist> getRadItems(List<ItemPackage> itemPackageList, BookRegiste bookRegiste) {
        List<ItemTableAssist> itemTableAssistList = new ArrayList<>();
        for (int i = 0; i < itemPackageList.size(); i++) {
            ItemPackage itemPackage = itemPackageList.get(i);
            RadiologyExamineItem radiologyExamineItem = radiologyExamineItemMapper.selByExamineItemId(itemPackage.getExamineItemId());
            ItemTableAssist itemTableAssist = new ItemTableAssist();

            itemTableAssist.setBookRegisteId(bookRegiste.getId());
            itemTableAssist.setExamineItemId(radiologyExamineItem.getExamineItemId());
            itemTableAssist.setItemName(radiologyExamineItem.getExamineName());
            itemTableAssist.setExamineArea(radiologyExamineItem.getExamineArea());
            itemTableAssist.setExamineMethod(radiologyExamineItem.getExamineMethod());

            FillRadItem fillRadItem = fillRadItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), radiologyExamineItem.getExamineItemId());
            if (fillRadItem != null) {
                itemTableAssist.setFilledStatus(fillRadItem.isFilled());
                itemTableAssist.setFillItemId(fillRadItem.getFillRadItemId());
            } else {
                fillRadItemMapper.insFillRadItem(bookRegiste.getId(), radiologyExamineItem.getExamineItemId());
                itemTableAssist.setFilledStatus(false);
                FillRadItem fillRadItem1 = fillRadItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), radiologyExamineItem.getExamineItemId());
                itemTableAssist.setFillItemId(fillRadItem1.getFillRadItemId());
            }
            itemTableAssistList.add(itemTableAssist);
        }
        return itemTableAssistList;
    }

    private List<ItemTableAssist> getSpeItems(List<ItemPackage> itemPackageList, BookRegiste bookRegiste) {
        List<ItemTableAssist> itemTableAssistList = new ArrayList<>();
        for (int i = 0; i < itemPackageList.size(); i++) {
            ItemPackage itemPackage = itemPackageList.get(i);
            SpeculumExamineItem speculumExamineItem = speculumExamineItemMapper.selByExamineItemId(itemPackage.getExamineItemId());

            ItemTableAssist itemTableAssist = new ItemTableAssist();
            itemTableAssist.setExamineSample(speculumExamineItem.getExamineSample());
            itemTableAssist.setItemName(speculumExamineItem.getExamineName());
            itemTableAssist.setExamineItemId(speculumExamineItem.getExamineItemId());
            itemTableAssist.setBookRegisteId(bookRegiste.getId());

            FillSpeItem fillSpeItem = fillSpeItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), speculumExamineItem.getExamineItemId());
            if (fillSpeItem != null) {
                itemTableAssist.setFilledStatus(fillSpeItem.isFilled());
                itemTableAssist.setFillItemId(fillSpeItem.getFillSpeItemId());
            } else {
                fillSpeItemMapper.insFillSpeItem(bookRegiste.getId(), speculumExamineItem.getExamineItemId());
                itemTableAssist.setFilledStatus(false);
                FillSpeItem fillSpeItem1 = fillSpeItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), speculumExamineItem.getExamineItemId());
                itemTableAssist.setFillItemId(fillSpeItem1.getFillSpeItemId());
            }
            itemTableAssistList.add(itemTableAssist);
        }
        return itemTableAssistList;
    }

    private List<ItemTableAssist> getMedItems(List<ItemPackage> itemPackageList, BookRegiste bookRegiste) {
        List<ItemTableAssist> itemTableAssistList = new ArrayList<>();
        for (int i = 0; i < itemPackageList.size(); i++) {
            ItemPackage itemPackage=itemPackageList.get(i);
            MedicalExamineItem medicalExamineItem=medicalExamineItemMapper.selByExamineItemId(itemPackage.getExamineItemId());
            ItemTableAssist itemTableAssist=new ItemTableAssist();
            itemTableAssist.setItemName(medicalExamineItem.getExamineName());
            itemTableAssist.setExamineItemId(medicalExamineItem.getExamineItemId());
            itemTableAssist.setBookRegisteId(bookRegiste.getId());

            FillMedItem fillMedItem=fillMedItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), medicalExamineItem.getExamineItemId());
            if(fillMedItem!=null){
                itemTableAssist.setFilledStatus(fillMedItem.isFilled());
                itemTableAssist.setFillItemId(fillMedItem.getFillMedItemId());
            }else{
                fillMedItemMapper.insFillMedItem(bookRegiste.getId(), medicalExamineItem.getExamineItemId());
                itemTableAssist.setFilledStatus(false);
                FillMedItem fillMedItem1=fillMedItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), medicalExamineItem.getExamineItemId());
                itemTableAssist.setFillItemId(fillMedItem1.getFillMedItemId());
            }
            itemTableAssistList.add(itemTableAssist);
        }
        return itemTableAssistList;
    }

    private List<ItemTableAssist> getCliItems(List<ItemPackage> itemPackageList, BookRegiste bookRegiste) {
        List<ItemTableAssist> itemTableAssistList = new ArrayList<>();
        for(int i=0; i<itemPackageList.size(); i++){
            ItemPackage itemPackage=itemPackageList.get(i);
            ClinicExamineItem clinicExamineItem=clinicExamineItemMapper.selByExamineItemId(itemPackage.getExamineItemId());
            ItemTableAssist itemTableAssist=new ItemTableAssist();
            itemTableAssist.setItemName(clinicExamineItem.getExamineName());
            itemTableAssist.setItemType(clinicExamineItem.getItemType());
            itemTableAssist.setExamineItemId(clinicExamineItem.getExamineItemId());
            itemTableAssist.setBookRegisteId(bookRegiste.getId());

            FillCliItem fillCliItem=fillCliItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), clinicExamineItem.getExamineItemId());
            if(fillCliItem!=null){
                itemTableAssist.setFilledStatus(fillCliItem.isFilled());
                itemTableAssist.setFillItemId(fillCliItem.getFillCliItemId());
            }else{
                fillCliItemMapper.insFillCliItem(bookRegiste.getId(), clinicExamineItem.getExamineItemId());
                itemTableAssist.setFilledStatus(false);
                FillCliItem fillCliItem1=fillCliItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), clinicExamineItem.getExamineItemId());
                itemTableAssist.setFillItemId(fillCliItem1.getFillCliItemId());
            }
            itemTableAssistList.add(itemTableAssist);
        }
        return itemTableAssistList;
    }

    private List<ItemTableAssist> getSupItems(List<ItemPackage> itemPackageList, BookRegiste bookRegiste) {
        List<ItemTableAssist> itemTableAssistList = new ArrayList<>();
        for (int i = 0; i < itemPackageList.size(); i++) {
            ItemPackage itemPackage = itemPackageList.get(i);
            SupersonicExamineItem supersonicExamineItem = supersonicExamineItemMapper.selByExamineItemId(itemPackage.getExamineItemId());
            ItemTableAssist itemTableAssist = new ItemTableAssist();
            itemTableAssist.setItemName(supersonicExamineItem.getExamineName());
            itemTableAssist.setExamineArea(supersonicExamineItem.getExamineArea());
            itemTableAssist.setExamineItemId(supersonicExamineItem.getExamineItemId());
            itemTableAssist.setBookRegisteId(bookRegiste.getId());

            FillSupItem fillSupItem = fillSupItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), supersonicExamineItem.getExamineItemId());
            if (fillSupItem != null) {
                itemTableAssist.setFilledStatus(fillSupItem.isFilled());
                itemTableAssist.setFillItemId(fillSupItem.getFillSupItemId());
            } else {
                fillSupItemMapper.insFillSupItem(bookRegiste.getId(), supersonicExamineItem.getExamineItemId());
                itemTableAssist.setFilledStatus(false);
                FillSupItem fillSupItem1 = fillSupItemMapper.selRecordByBookIdAndItemId(bookRegiste.getId(), supersonicExamineItem.getExamineItemId());
                itemTableAssist.setFillItemId(fillSupItem1.getFillSupItemId());
            }
            itemTableAssistList.add(itemTableAssist);
        }
        return itemTableAssistList;
    }
}
